package uk.ac.glasgow.demosocs.tests;

import static org.junit.Assert.*;

import java.util.Date;

import org.junit.Before;
import org.junit.Test;

import uk.ac.glasgow.demosocs.Election;
import uk.ac.glasgow.demosocs.VotingSystem;

public class ScheduleElectionTest {
	private VotingSystem vs;
	
	@Before
	public void setUp() throws Exception {
		//vs = new VotingSystem();
		vs.setCurrentUser("admin", "passwrd");
	}

	@Test
	public void test() {
		vs.createElection("Test Election", "AV");
		
		Election e = vs.getCurrentElection();
		assertNotNull("Current election not set.", e);
		
		@SuppressWarnings("deprecation") Date nominationDate = new Date(2012, 2, 14);
		@SuppressWarnings("deprecation") Date startDate = new Date(2012, 2, 15);
		@SuppressWarnings("deprecation") Date endDate = new Date(2012, 2, 22);
		
		vs.editElection(nominationDate, startDate, endDate, e.getEID());
		assertEquals("Open date not set.", e.getOpenNominations(), nominationDate);
		assertEquals("Start date not set.", e.getStart(), startDate);
		assertEquals("End date not set.", e.getEnd(), endDate);
		
		boolean existsInSet = false;
		for (Election f: vs.getElections())
			if (f.equals(e)) {
				existsInSet = true;
				break;
			}
		assertTrue("Not in election set.", existsInSet);
	}
}
